/*
*    Qizx/open 3.0 beta
*
* This code is the open-source version of Qizx.
* Copyright (C) 2004-2009 Axyana Software -- All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License 
*  Version 1.1 (the "License"); you may not use this file except in 
*  compliance with the License. You may obtain a copy of the License at
*  http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
*  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
*  for the specific language governing rights and limitations under the
*  License.
*
* The Initial Developer of the Original Code is Xavier Franc - Axyana Software.
*
*/
using System;
namespace System.Qizx.Api {

    /// <summary>
    /// Qualified name for XML elements and attributes.
    /// <para>
    /// The {@link ItemFactory} interface is normally invoked for creating the
    /// QName's used in the API. It is recommended to cache QNames when possible for
    /// better performance.
    /// </para>
    /// Mandatory requirements for an implementation of this interface:
    /// <ul>
    /// 		<li>The hashCode() and equals() methods must be properly implemented.</li>
    /// 	</ul>
    /// </summary>
    public class QName : System.Xml.XmlQualifiedName, IComparable<QName> {
        //public interface QName {

        /// <summary> Returns an optional prefix associated with the QName (may be null).</summary>
        /// <returns> a String representing the prefix value
        /// </returns>
        public virtual string Prefix {
            get {
                return string.Empty;
            }
        }

        public int CompareTo(System.Xml.XmlQualifiedName other) {
            int value = this.Namespace.CompareTo(other.Namespace);
            if (value == 0) {
                return this.Name.CompareTo(other.Name);
            }
            return value;
        }

        public int CompareTo(QName other) {
            int value = this.Namespace.CompareTo(other.Namespace);
            if (value == 0) {
                return this.Name.CompareTo(other.Name);
            }
            return value;
        }

        /// <summary>
        /// Equalses the specified other.
        /// </summary>
        /// <param name="other">The other.</param>
        /// <returns></returns>
        public bool Equals(System.Xml.XmlQualifiedName other) {
            if (other == null) return false;
            if (other == this) return true;
            return this.GetHashCode() == other.GetHashCode() && this.Name == other.Name && this.Namespace == other.Namespace;
        }

        /// <summary>
        /// Empty QName
        /// </summary>
        public static new readonly QName Empty;
        public static readonly QName[] EmptyArray;
        public static readonly QName XsiNil;
        static QName() {
            Empty = new QName(string.Empty, string.Empty);
            EmptyArray = new QName[0];
            XsiNil = System.Qizx.Xdm.IQName.GetQName(System.Xml.Schema.XmlSchema.InstanceNamespace, "nil");
        }

        // Summary:
        //     Initializes a new instance of the System.Xml.XmlQualifiedName class.
        public QName() : base() { }
        //
        // Summary:
        //     Initializes a new instance of the System.Xml.XmlQualifiedName class with
        //     the specified name.
        //
        // Parameters:
        //   name:
        //     The local name to use as the name of the System.Xml.XmlQualifiedName object.
        public QName(string name) : base(name) { }
        //
        // Summary:
        //     Initializes a new instance of the System.Xml.XmlQualifiedName class with
        //     the specified name and namespace.
        //
        // Parameters:
        //   name:
        //     The local name to use as the name of the System.Xml.XmlQualifiedName object.
        //
        //   ns:
        //     The namespace for the System.Xml.XmlQualifiedName object.
        public QName(string name, string ns) : base(name, ns) { }

        /// <summary> Returns true if this QName has the empty namespace URI.</summary>
        /// <returns> true if this QName has the empty namespace URI.
        /// </returns>
        public bool HasNoNamespace() { return this.Namespace.Length == 0; }
    }
}